<template>
  <basic-container>
    <div class="gather-content-right-main">
      <div class="login-form-content">
        <div class="login-form-hint">
          您好，欢迎参加{{ trialForm.name }}，您的数据将被妥善保管，非经您本人同意，不会用于其他商用
        </div>
        <div class="login-form-btn">
          <el-button type="primary" class="back-btn" @click="handleLogin(0)">登 录</el-button>
          <el-button
            type="success"
            class="back-btn"
            plain
            style="margin-left: 0"
            @click="handleLogin(1)"
            >新 建</el-button
          >
          <span style="text-align: center"
            >若已新建请点击“登录”按钮；若新建信息请点击“新建”按钮</span
          >
        </div>
      </div>
    </div>
  </basic-container>
</template>
<script setup>
import { Back, Check, DArrowRight, DArrowLeft } from '@element-plus/icons-vue';
import { getTrialDetail } from '@/api/trial/trial';
import { add, nmCreateByPhone } from '@/api/clinicalcase/clinicalCase';
// import VFormRender from '@/components/form-render/index.vue';
import { treeWithCrf } from '@/api/group/group';
import { getDetail } from '@/api/crf/crf.js';
import { ref, reactive, computed, onMounted, defineEmits, nextTick } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useStore } from 'vuex';
const store = useStore();
const router = useRouter();
const route = useRoute();
const routerQuery = ref({});
routerQuery.value = route.query;
const formJson = ref({});
const vFormRef = ref(null);
const formData = ref({});
const optionData = ref({});
let nextCrfTreeNum = ref(0);
let treeWithCrfList = ref([]);
let trialForm = ref({});
onMounted(() => {
  if (routerQuery.value.trialId) {
    getTrialDetail(routerQuery.value.trialId).then(res => {
      trialForm.value = res.data.data;
    });
  }
});
// 登录/新建按钮
/* 
  type 0:登录
  type 1:新建
  routerQuery.value.patternValue 1:患者
  routerQuery.value.patternValue 2:匿名
*/
const handleLogin = type => {
  if (routerQuery.value.patternValue == '1') {
    router.push({
      path: '/CrfH5/login',
      query: {
        ...routerQuery.value,
        loginType: type,
      },
    });
  } else {
    if (type === 0) {
      router.push({
        path: '/CrfH5/login',
        query: {
          ...routerQuery.value,
          loginType: type,
        },
      });
    } else {
      let formData = {
        name:'新建者',
        trial: routerQuery.value.trialId,
        groupId: routerQuery.value.groupId,
        // researcher:trialForm.value.researcher,
        hospitalDept:trialForm.value.researchInstitution,
      };
      nmCreateByPhone(formData.groupId,formData.trial)
      .then((res) => {
        console.log(res);
        routerQuery.value.caseUserId = res.data.data.id;
        routerQuery.value.groupId = res.data.data.groupId;
        // ElMessage.success('操作成功!');
        router.replace({
          path: '/CrfH5/FillCrf',
          query: {
            ...routerQuery.value,
          },
        });
      })
      .catch(error => {
        // window.console.console.log(error);
      });
    }
  }
};
</script>
<style scoped>
.login-form-content {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.login-form-hint {
  width: 90%;
  height: 100px;
  margin: 50px 0;
  color: black;
  font-size: 20px;
  text-align: center;
}
.login-form-btn {
  width: 90%;
  height: aut;
  display: flex;
  flex-direction: column;
  /* justify-content: space-between; */
  color: black;
  font-size: 18px;
}
.back-btn {
  width: 100%;
  height: 50px;
  border-radius: 20px;
  margin-bottom: 45px;
  font-size: 18px;
}
</style>